/**
 * @author LKQ
 * @date 2021/12/5 21:22
 * @description 使用递归的方法
 */
public class Solution {
    public static void main(String[] args) {
        TreeNode leaf4 = new TreeNode(4, null, null);
        TreeNode leaf3 = new TreeNode(3, null, null);
        TreeNode leaf2 = new TreeNode(2, leaf4, leaf3);
        TreeNode leaf1 = new TreeNode(2, leaf3, leaf4);
        TreeNode root = new TreeNode(1, leaf1, leaf2);
        Solution solution = new Solution();
        System.out.println(solution.isSymmetric(root));
    }

    public boolean isSymmetric(TreeNode root) {
        return check(root, root);
    }

    public boolean check(TreeNode p, TreeNode q) {
        if (p == null && q == null) {
            return true;
        }
        if (p == null || q == null) {
            // 左子树为空或者右子树为空
            return false;
        }
        return p.val == q.val && check(p.left, q.right) && check(p.right, q.left);
    }
}
